package cn.opopopo.wordexport.mode.export;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.resource.ClassPathResource;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.util.Units;
import org.apache.poi.xwpf.usermodel.*;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.net.URLEncoder;

import static cn.opopopo.wordexport.util.DocumentToByteArray.convertXWPFDocumentToByteArray;
@Service
public enum ExportFileEnum {


    APPROVAL_RECORD{
        @Override
        public byte[] data(String id) throws IOException, InvalidFormatException {
            return super.data(id);
        }
        @Override
        public String suffix(){
            return ".docx";
        }

        @Override
        public String fileName(){
            return "";
        }
    },

    ANNEX{
        @Override
        public byte[] data(String id) throws IOException, InvalidFormatException {
            return super.data(id);
        }
        @Override
        public String suffix(){
            return ".docx";
        }

        @Override
        public String fileName(){
            return "";
        }
    },



    CIRCULATION{
        @Override
        public byte[] data(String id) throws IOException, InvalidFormatException {
            XWPFDocument document = new XWPFDocument();
            XWPFParagraph paragraph = document.createParagraph();
            XWPFRun run = paragraph.createRun();
            run.setText("Hello, World!");
            run.setTextHighlightColor("blue");
            XWPFTable table = document.createTable(4,4);
            // 添加表格内容
            table.getRow(0).getCell(0).setText("1");
            table.getRow(0).getCell(1).setText("张三");
            table.getRow(0).getCell(2).setText("李四");
            table.getRow(0).getCell(3).setText("王五");
            table.getRow(1).getCell(0).setText("5");
            table.getRow(1).getCell(1).setText("6");
            table.getRow(1).getCell(2).setText("7");
            table.getRow(1).getCell(3).setText("8");
            table.getRow(2).getCell(0).setText("9");
            table.getRow(2).getCell(1).setText("10");
            table.getRow(2).getCell(2).setText("11");
            table.getRow(2).getCell(3).setText("12");
            table.getRow(3).getCell(0).setText("13");
            table.getRow(3).getCell(1).setText("14");
            table.getRow(3).getCell(2).setText("15");
            table.getRow(3).getCell(3).setText("16");
            // 添加图片
            XWPFParagraph imageParagraph = document.createParagraph();
            XWPFRun imageRun = imageParagraph.createRun();
            ClassPathResource resource = new ClassPathResource("staic/57c6-fxpwyhw5134340.jpg");
            imageRun.addPicture(resource.getStream(), Document.PICTURE_TYPE_JPEG, "57c6-fxpwyhw5134340.jpg", Units.toEMU(200), Units.toEMU(200));
            // 设置中文文件名称
            String childFileName = URLEncoder.encode(DateUtil.format(DateUtil.date(), DatePattern.CHINESE_DATE_TIME_PATTERN), "UTF-8");
            return convertXWPFDocumentToByteArray(document);
        }
        @Override
        public String suffix(){
            return ".docx";
        }

        @Override
        public String fileName(){
            return "xxx";
        }
    },


    FORM_DATA{
        @Override
        public byte[] data(String id) throws IOException, InvalidFormatException {

            XWPFDocument document = new XWPFDocument();
            XWPFParagraph paragraph = document.createParagraph();
            XWPFRun run = paragraph.createRun();
            run.setText("Hello, World!");
            run.setTextHighlightColor("blue");
            XWPFTable table = document.createTable(4,4);
            // 添加表格内容
            table.getRow(0).getCell(0).setText("1");
            table.getRow(0).getCell(1).setText("张三");
            table.getRow(0).getCell(2).setText("李四");
            table.getRow(0).getCell(3).setText("王五");
            table.getRow(1).getCell(0).setText("5");
            table.getRow(1).getCell(1).setText("6");
            table.getRow(1).getCell(2).setText("7");
            table.getRow(1).getCell(3).setText("8");
            table.getRow(2).getCell(0).setText("9");
            table.getRow(2).getCell(1).setText("10");
            table.getRow(2).getCell(2).setText("11");
            table.getRow(2).getCell(3).setText("12");
            table.getRow(3).getCell(0).setText("13");
            table.getRow(3).getCell(1).setText("14");
            table.getRow(3).getCell(2).setText("15");
            table.getRow(3).getCell(3).setText("16");
            // 添加图片
            XWPFParagraph imageParagraph = document.createParagraph();
            XWPFRun imageRun = imageParagraph.createRun();
            ClassPathResource resource = new ClassPathResource("staic/57c6-fxpwyhw5134340.jpg");
            imageRun.addPicture(resource.getStream(), Document.PICTURE_TYPE_JPEG, "57c6-fxpwyhw5134340.jpg", Units.toEMU(200), Units.toEMU(200));
            // 设置中文文件名称
            String childFileName = URLEncoder.encode(DateUtil.format(DateUtil.date(), DatePattern.CHINESE_DATE_TIME_PATTERN), "UTF-8");

            return convertXWPFDocumentToByteArray(document);
        }
        @Override
        public String suffix(){
            return ".docx";
        }

        @Override
        public String fileName(){
            return "表单";
        }
    };

    public byte[] data(String id) throws IOException, InvalidFormatException {
        throw new AbstractMethodError();
    }

    public String suffix() {
        throw new AbstractMethodError();
    }

    public String fileName() {
        throw new AbstractMethodError();
    }


}
